#if !defined(AFX_MAINPANEL_H__07E96A3A_B979_48C7_9E72_795D3CAFC77D__INCLUDED_)
#define AFX_MAINPANEL_H__07E96A3A_B979_48C7_9E72_795D3CAFC77D__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MainPanel.h : header file
//

#include "BaseMethodCallback.h"
#include "LoginDlg.h"

#define WM_APP_CREATEMAINPANEL  (WM_APP+100)
#define WM_APP_DESTROYMAINPANEL (WM_APP+101)

#define WM_APP_OPTIONSSAVED   (WM_APP+200)

#define WM_APP_USERDEFINEDDISPLAYREADY        (WM_APP+330)
#define WM_APP_USERDEFINEDDISPLAYCONTENTREADY (WM_APP+340)
#define WM_APP_USERDEFINEDDISPLAYFAILURE      (WM_APP+350)

#define BTNID_ABOUTBOX          1
#define BTNID_CHANGEPASSWORD    2
#define BTNID_SETOPTION         3
#define BTNID_ARRANGEPANELS     4
#define BTNID_CLOSEALLPANELS    5
#define BTNID_SELECTMONUNIT     6
#define BTNID_REPORTMANAGEMENT  7

#define OPM_GENERAL   0x1
#define OPM_DISPLAY   0x2
#define OPM_COLOR     0x4
#define OPM_CURVE     0x8
#define OPM_ALARM     0x10

class CMainTreeView;
class CMainHtmlView;
class CCtrlBar;
class CBasePanel;
class CCoalMinePanel;
class CMonUnitPanel;
class CAlarmDataPanel;
class BaseCoalMineUnit;
class BaseMonitoringUnit;
class CAlarmAnimationWnd;
class CSelectDlg;
class UserDefinedDisplay;
class CUserDefinedDisplayPanel;
class UserDefinedDisplayManager;

/////////////////////////////////////////////////////////////////////////////
// CMainPanel window

class CMainPanel : public CFrameWnd, public BaseMethodCallback
{
// Construction
protected:
	CMainPanel();
	virtual ~CMainPanel();

// Attributes
protected:
	
	CWnd * m_pParentWnd;
	CCtrlBar * m_pCtrlBar;
	CSplitterWnd m_wndSplitter;
  std::vector<CBasePanel *> m_Panels;
  CPoint m_ptPanelTopLeft;
  CAlarmAnimationWnd * m_pAlarmAnimationWnd;
  CSelectDlg * m_pSelectDlg;
  UserDefinedDisplayManager * m_pUserDefinedDisplayManager;
  BaseMethodPerformer * m_pPerformer;


// Operations
public:
  UINT m_nIdTimerLogin;   //Timer to Relogin
  void WaitToRelogin();
  CLoginDlg * m_pLoginDlg;

  virtual void Callback(BaseMethodPerformer * pPerformer);
	virtual bool Create(bool bPopup, const CRect& rect, CWnd * pParentWnd);
  CMainTreeView * GetpTreeView() const {return (CMainTreeView *)(m_wndSplitter.GetPane(0, 0));}
  CMainHtmlView * GetpHtmlView() const {return (CMainHtmlView *)(m_wndSplitter.GetPane(0, 1));}
  void AddPanel(CBasePanel * pPanel);
  void RemovePanel(CBasePanel * pPanel);
  void DestroyAllPanels();
  void OpenCoalMinePanel(long nCoalMineId, int nSurfaceIndex = 0);
  CCoalMinePanel * GetpCoalMinePanelById(long nCoalMineId) const;
  void OpenMonUnitPanel(long nCoalMineId, const CString& strId, int nSurfaceIndex = 0);
  CMonUnitPanel * GetpMonUnitPanelById(long nCoalMineId, const CString& strId) const;
  void OpenUserDefinedDisplayPanel(UserDefinedDisplay * pUserDefinedDisplay);
  bool OpenUserDefinedDisplayPanel(const CString& strUserId, const CString& strDisplayName);
  CUserDefinedDisplayPanel * GetpUserDefinedDisplayPanelById(UserDefinedDisplay * pUserDefinedDisplay) const;
  void UpdateDisplay();
  void UpdateDefinitionDisplay(BaseCoalMineUnit * pCoalMineUnit);
  void UpdateDataDisplay(BaseCoalMineUnit * pCoalMineUnit, BaseMonitoringUnit * pMonitoringUnit);
  void OpenAlarmDataPanel(bool bShow = true);
  CAlarmDataPanel * GetpAlarmDataPanel() const;
  void ApplyOptions(DWORD dwOptionPagesMask);
  void ArrangePanels();
  void CreateAlarmAnimationWnd();
  void OpenAlarmAnimationWnd();
  void CloseAllPanels();
  void OpenSelectDlg();
  void DeleteSelectDlg();
  UserDefinedDisplayManager * GetpUserDefinedDisplayManager() const {return m_pUserDefinedDisplayManager;}
  void DestroyUserDefinedDisplayPanelById(UserDefinedDisplay * pUserDefinedDisplay);
  void ButtonClicked(int nButtonId);
  void AboutBox();
  void ChangePassword();
  void SetOption();
  void ReportManagement();
  bool AddUserDefinedDisplay(const CString& strDisplayName, BYTE nShareFlag);
  bool DeleteUserDefinedDisplay(const CString& strUserId, const CString& strDisplayName);
  bool RenameUserDefinedDisplay(const CString& strUserId, const CString& strOldDisplayName, const CString& strNewDisplayName);

protected:
  CRect GetPanelRect(CBasePanel * pPanel);

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMainPanel)
	protected:
	virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
	virtual void PostNcDestroy();
	//}}AFX_VIRTUAL

// Implementation
public:
  static CMainPanel * Instance();

	// Generated message map functions
protected:
	//{{AFX_MSG(CMainPanel)
	afx_msg void OnDestroy();
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnClose();
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
	afx_msg void OnAddUserDefinedDisplay();
	afx_msg void OnDeleteUserDefinedDisplay();
	//}}AFX_MSG
  afx_msg LRESULT OnReceived(WPARAM wParam, LPARAM lParam);
  afx_msg LRESULT OnDisconnected(WPARAM wParam, LPARAM lParam);
  afx_msg LRESULT OnOptionsSaved(WPARAM wParam, LPARAM lParam);
  afx_msg LRESULT OnUserDefinedDisplayReady(WPARAM wParam, LPARAM lParam);
  afx_msg LRESULT OnUserDefinedDisplayContentReady(WPARAM wParam, LPARAM lParam);
  afx_msg LRESULT OnUserDefinedDisplayFailure(WPARAM wParam, LPARAM lParam);
	DECLARE_MESSAGE_MAP()
private:
  static CMainPanel * m_pInstance;
};

extern CMainPanel * g_pMainPanel;

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MAINPANEL_H__07E96A3A_B979_48C7_9E72_795D3CAFC77D__INCLUDED_)
